package com.nd.rj.common;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;

import com.nd.rj.common.login.interfaceImpl.NdLogin99PlatformImpl;
import com.nd.rj.common.login.loginInterface.INdLogin99PlatformOperate;
import com.nd.rj.common.register.INdRegistManagerOperate;
import com.nd.rj.common.register.IRegisterationListener;
import com.nd.rj.common.register.NdRegistManagerImpl;
import com.nd.rj.common.thirdPlatformAuth.IOperate.IThirdPlatformAuthOperate;
import com.nd.rj.common.thirdPlatformAuth.operateImpl.ThirdPlatformAuthImpl;


/**
 * 登录注册对外接口类
 * 
 * <br>Created 2014-10-21 下午9:40:05
 * @version  
 * @author   linsj		
 *
 * @see 	 
 * 
 * Copyright(c) 2009-2014, TQ Digital Entertainment, All Rights Reserved
 *
 */
public class LoginRegisterFactory {
    /**注册操作接口*/
    private INdRegistManagerOperate mIRegistOperate;
    
    /**99帐号登录操作接口*/
    private INdLogin99PlatformOperate mINdLoginOperate;
    
    /**第三方平台授权操作接口*/
    private IThirdPlatformAuthOperate mIThirdAuthOperate;
    
    /**
     * 获取注册管理类实例
     * 
     * <br>Created 2014-10-22 下午11:21:00
     * @param listener          注册结果监听接口
     * @param bNeedWaitDlg      是否需要显示等待对话框
     * @param waitDlg           在需要显示等待对话框的前提下，显示该等待对话框，传null时，为系统默认对话框
     * @return                  注册管理接口
     * @author       linsj
     */
    public INdRegistManagerOperate getRegisterOpereate(IRegisterationListener listener,
            boolean bNeedWaitDlg, Dialog waitDlg) {
        if (null == mIRegistOperate) {
            mIRegistOperate = new NdRegistManagerImpl();
        }

        mIRegistOperate.setIsNeedWaitDlg(bNeedWaitDlg);
        mIRegistOperate.setRegisterListener(listener);
        mIRegistOperate.setRegisterWaitDlg(waitDlg);

        return mIRegistOperate;
    }
    
    /**
     * 获取登录99平台接口
     * 
     * <br>Created 2014-10-22 下午11:21:00
     * @param context       上下文
     * @param bForceInit    是否要强制初始化
     * @param waitDlg       操作时显示该等待对话框，传null时，为系统默认对话框
     * @return              登录99平台接口
     * @author       linsj
     */
    public INdLogin99PlatformOperate getLogin99PlatformOperate(Context context, boolean bForceInit,
            Dialog waitDlg) {
        if (null == mINdLoginOperate) {
            mINdLoginOperate = new NdLogin99PlatformImpl(context);
            mINdLoginOperate.doInit99Platform();
        }else if(bForceInit){
            mINdLoginOperate.doInit99Platform();
        }
        mINdLoginOperate.setLogin99WaitDlg(waitDlg);

        return mINdLoginOperate;
    }
    
    /**
     * 获取第三方平台登录授权接口
     * 
     * <br>Created 2014-10-22 下午11:21:00
     * @param activity      activity
     * @param iPlatformType 平台类型，
     *                          新浪微博:THIRD_PLATFORM_TYPE.THIRD_PLATFORM_SINA_WEIBO
     *                          QQ：THIRD_PLATFORM_TYPE.THIRD_PLATFORM_QQ
     * @param waitDlg       操作时显示该等待对话框，传null时，为系统默认对话框
     * @return              第三方平台登录授权接口
     * @author       linsj
     */
    public IThirdPlatformAuthOperate getThirdPlatformLoginOpereate(Activity activity,
            int iPlatformType, Dialog waitDlg) {
        if (null == mIThirdAuthOperate) {
            mIThirdAuthOperate = new ThirdPlatformAuthImpl(activity);
        }
        mIThirdAuthOperate.setThirdPlatformType(iPlatformType);
        mINdLoginOperate.setLogin99WaitDlg(waitDlg);

        return mIThirdAuthOperate;
    }
    
    /**
     * 单实例内部类
     * 
     * <br>Created 2014-10-21 下午9:40:52
     * @version  LoginRegisterFactory
     * @author   linsj		
     *
     * @see 	 
     * 
     * Copyright(c) 2009-2014, TQ Digital Entertainment, All Rights Reserved
     *
     */
    private static class SingletonHolder {
        private static final LoginRegisterFactory INSTANCE = new LoginRegisterFactory();
    }
    
    /**
     * 构造方法
     * 
     * <br>Created 2014-10-21 下午9:40:36
     * @author       linsj
     */
    private LoginRegisterFactory() {
    }

    /**
     * 获取实例
     * 
     * <br>Created 2014-10-21 下午9:41:10
     * @return
     * @author       linsj
     */
    public static LoginRegisterFactory getInstance() {
        return SingletonHolder.INSTANCE;
    }
}
